package wsi.task.map;

import org.rygh.core.face.IHasKey;
import org.rygh.core.model.common.StringSet;
import org.rygh.core.xml.XmlPath;

public class StatisticsKey implements IHasKey<StatisticsKey> {
	private final XmlPath sourceXPath;
	private final XmlPath destXPath;
	private final StringSet predicates;

	public StatisticsKey(XmlPath sourceXPath, XmlPath destXPath,
			StringSet predicates) {
		this.sourceXPath = sourceXPath;
		this.destXPath = destXPath;
		this.predicates = predicates;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		StatisticsKey other = (StatisticsKey) obj;
		if (destXPath == null) {
			if (other.destXPath != null)
				return false;
		} else if (!destXPath.equals(other.destXPath))
			return false;
		if (predicates == null) {
			if (other.predicates != null)
				return false;
		} else if (!predicates.equals(other.predicates))
			return false;
		if (sourceXPath == null) {
			if (other.sourceXPath != null)
				return false;
		} else if (!sourceXPath.equals(other.sourceXPath))
			return false;
		return true;
	}

	public XmlPath getDestXPath() {
		return destXPath;
	}

	@Override
	public StatisticsKey getKey() {
		return this;
	}

	public StringSet getPredicates() {
		return predicates;
	}

	public XmlPath getSourceXPath() {
		return sourceXPath;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((destXPath == null) ? 0 : destXPath.hashCode());
		result = prime * result
				+ ((predicates == null) ? 0 : predicates.hashCode());
		result = prime * result
				+ ((sourceXPath == null) ? 0 : sourceXPath.hashCode());
		return result;
	}

}
